<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>位置</title>
</head>
<body>
<div id="data"></div>
</body>
<script src="js/jquery.min.js"></script>
<script src="js/alert.js"></script>
<script src="http://res.wx.qq.com/open/js/jweixin-1.4.0.js"></script>
<script>
    $(document).ready(function () {
        run()
        });

    function run() {
        var url = window.location.href;
        $.ajax({
            "url": "/wechat/weizhi/",
            "data": "uri=" + url,
            "type": "POST",
            "dataType": "json",
            "success": function (json) {
                var map = json.data;
                wxconfig(map);
            }
        })
    }

    function wxconfig(data) {

        wx.config({
           // debug: data.debug, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
            appId: data.appId, // 必填，公众号的唯一标识
            timestamp: data.timestamp, // 必填，生成签名的时间戳
            nonceStr: data.nonceStr, // 必填，生成签名的随机串
            signature: data.signature,// 必填，签名
            jsApiList: ['getLocation'] // 必填，需要使用的JS接口列表
        });

        wx.error(function (res) {

        });
        wx.ready(function(){
            wx.getLocation({
                type: 'wgs84', // 默认为wgs84的gps坐标，如果要返回直接给openLocation用的火星坐标，可传入'gcj02'
                success: function (res) {
                    var latitude = res.latitude; // 纬度，浮点数，范围为90 ~ -90
                    var longitude = res.longitude; // 经度，浮点数，范围为180 ~ -180。
                    var speed = res.speed; // 速度，以米/每秒计
                    var accuracy = res.accuracy; // 位置精度

                    $("#data").append(latitude);
                    $("#data").append(longitude);

                    $.ajax({
                        url: "https://api.map.baidu.com/geocoder/v2/?ak=2GhAjyOSR2zqbv2o4MaMIEHY3ieP1ixC&callback=renderReverse&location=" + latitude + "," + longitude + "&output=json&pois=1",
                        type: "get",
                        dataType: "jsonp",
                        jsonp: "callback",
                        success: function (data) {
                            var province = data.result.addressComponent.province;
                            var cityname = (data.result.addressComponent.city);
                            var district = data.result.addressComponent.district;
                            var street = data.result.addressComponent.street;
                            var street_number = data.result.addressComponent.street_number;
                            var address = data.result.formatted_address;

                            $("#data").append('<div>province='+province+'</div>');
                            $("#data").append('<div>cityname='+cityname+'</div>');
                            $("#data").append('<div>district='+district+'</div>');
                            $("#data").append('<div>street='+street+'</div>');
                            $("#data").append('<div>street_number='+street_number+'</div>');
                            $("#data").append('<div>address='+address+'</div>');

                            var data = province+cityname+district+street;
                            get(data);
                        }
                    });

                }
            });

          });


    }
    function get(data) {

        $.ajax({
            "url": "/wechat/sout/",
            "data": "data=" + data,
            "type": "POST",
            "success": function () {

            }
        })
    }
</script>
</html>